package com.zhangxu.microservice.employee.web.mapstruct;

import com.zhangxu.microservice.common.utils.AesEncryptUtils;
import com.zhangxu.microservice.common.utils.DesensitizationUtils;
import com.zhangxu.microservice.employee.api.response.EmployeeApiDTO;
import com.zhangxu.microservice.employee.web.request.CreateEmployeeReq;
import com.zhangxu.microservice.employee.api.response.EmployeeAuthDTO;
import com.zhangxu.microservice.employee.domain.dto.CreateEmployeeDTO;
import com.zhangxu.microservice.employee.domain.dto.EmployeeDTO;
import com.zhangxu.microservice.employee.web.response.EmployeeResp;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.List;

@Mapper(componentModel = "spring")
public interface EmployeeConverter {

    @Mapping(target = "passwordCrypto", ignore = true)
    @Mapping(target = "phoneCrypto", ignore = true)
    CreateEmployeeDTO toCreateEmployeeDTO(CreateEmployeeReq createUserRequest);

    EmployeeAuthDTO toEmployeeAuthDTO(EmployeeDTO userDTO);

    @Mapping(target = "phone", source = "phoneCrypto", qualifiedByName = "desensitizePhone")
    EmployeeResp dto2EmployeeResp(EmployeeDTO dto);

    @Named("desensitizePhone")
    static String desensitizePhone(String phone) {
        return DesensitizationUtils.desensitizePhone(AesEncryptUtils.decrypt(phone));
    }

    EmployeeApiDTO toEmployeeDTO(EmployeeDTO userDTO);

    List<EmployeeApiDTO> toEmployeeDTOList(List<EmployeeDTO> employeeDTOList);
}
